Skip to content

Redact auth in wheel cache origin warnings - #14233

Open
carrerasdarren-cell wants to merge 1 commit into
pypa:mainfrom
carrerasdarren-cell:fix/cache-origin-redact-auth
Open

Redact auth in wheel cache origin warnings#14233
carrerasdarren-cell wants to merge 1 commit into
pypa:mainfrom
carrerasdarren-cell:fix/cache-origin-redact-auth

Conversation

@carrerasdarren-cell

Copy link
Copy Markdown

What does this PR do?

Fixes #14232.

record_download_origin() writes a credential-stripped PEP 610 URL to origin.json, but previously compared and logged the raw in-memory URL. Re-recording an authenticated origin therefore produced a false mismatch warning containing the username and password.

This change compares the same serialized URL representation that is written to disk and uses those stripped values in genuine mismatch warnings. It adds regression coverage for both behaviors.

PR Checklist:

  • I agree to follow the PSF Code of Conduct.
  • I have read and have followed the CONTRIBUTING.md file.
  • I have added a news file fragment.
  • I have read and followed the AI_POLICY.md file, and I take full ownership and responsibility for every line.

Assisted-by: OpenAI Codex

Tests

  • pytest -q tests/unit/test_cache.py: 10 passed
  • Black 26.5.1 passed
  • Ruff 0.15.20 passed
  • Mypy 2.1.0 passed for both changed Python files
  • git diff --check passed

@sbidoul sbidoul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks generally good. A couple of minor remarks.

# TODO: use DirectUrl.equivalent when
# https://github.com/pypa/pip/pull/10564 is merged.
if origin.url != download_info.url:
origin_url = origin.to_dict_compat()["url"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary, since origin comes from an already serialized source, which is already stripped)?

@staticmethod
def record_download_origin(cache_dir: str, download_info: DirectUrl) -> None:
origin_path = Path(cache_dir) / ORIGIN_JSON_NAME
download_url = download_info.to_dict_compat()["url"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be moved just before the test since computing it is not necessary if origin_path does not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wheel cache origin mismatch warning exposes URL credentials

2 participants